/*
 * 작성자 : Jint
 * 작성일 : 140421
 * 내용 : 
 */

package member2;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Main extends JFrame {
	
	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu jmenu;
	private JMenuItem mntmInput;
	private JMenuItem mntmOutput;
	private JMenuItem mntmModify;
	private JMenuItem mntmDelete;
	ArrayList<Data> list = new ArrayList<Data>();
	// list에 저장되려고 하는 타입이 Data이다. Data형식으로 받을것이기 때문에, 이 작업을 안하면 나중에 하나하나 다 캐스팅 해줘야한다.
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public Main() {
		setTitle("Member Management Program");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 485, 370);
		setJMenuBar(getMenuBar_2());
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}
	private JMenuBar getMenuBar_2() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.add(getJmenu());
		}
		return menuBar;
	}
	private JMenu getJmenu() {
		if (jmenu == null) {
			jmenu = new JMenu("Manage");
			jmenu.add(getMntmInput());
			jmenu.add(getMntmOutput());
			jmenu.add(getMntmModify());
			jmenu.add(getMntmDelete());
		}
		return jmenu;
	}
	private JMenuItem getMntmInput() {
		if (mntmInput == null) {
			mntmInput = new JMenuItem("Input");
			mntmInput.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Input i = new Input(list);
					
					contentPane.removeAll();
					contentPane.add(i);
					contentPane.updateUI();
				}
			});
		}
		return mntmInput;
	}
	private JMenuItem getMntmOutput() {
		if (mntmOutput == null) {
			mntmOutput = new JMenuItem("Output");
			mntmOutput.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Output o = new Output(list);
					
					contentPane.removeAll();
					contentPane.add(o);
					contentPane.updateUI();
				}
			});
		}
		return mntmOutput;
	}
	private JMenuItem getMntmModify() {
		if (mntmModify == null) {
			mntmModify = new JMenuItem("Modify");
			mntmModify.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Modify m = new Modify();
					
					contentPane.removeAll();
					contentPane.add(m);
					contentPane.updateUI();
				}
			});
		}
		return mntmModify;
	}
	private JMenuItem getMntmDelete() {
		if (mntmDelete == null) {
			mntmDelete = new JMenuItem("Delete");
			mntmDelete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Delete d = new Delete();
					
					contentPane.removeAll();
					contentPane.add(d);
					contentPane.updateUI();
				}
			});
		}
		return mntmDelete;
	}
}
